package com.gamesnet.ihm;

import org.json.JSONException;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;

import com.gamesnet.api.Api;
import com.gamesnet.api.Session;
import com.gamesnet.models.Utilisateur;
import com.gamesnet.util.TabColors;
import com.gamesnet.widget.ActionBar;
import com.gamesnet.widget.ActionBar.IntentAction;

public class CompteActivity extends TabActivity implements OnTabChangeListener{

	private TabHost tabs;
	Utilisateur user = null;
	long userId = 0;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.moncompte);

		Bundle b = getIntent().getExtras();
		Log.v("compteactivity",getIntent().toString());
		userId = b.getLong("userId");

		if(Session.getInstance().getUser().getId() == userId)
			user = Session.getInstance().getUser();
		else{
			try {
				user = Api.getUser(String.valueOf(userId));
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		final ActionBar actionBar = (ActionBar) findViewById(R.id.actionbarHaut);
		actionBar.setHomeAction(new IntentAction(this, new Intent(this, DashboardActivity.class), R.drawable.home));
		actionBar.setTitre(user.getPrenom()+" "+user.getNom());

		tabs = getTabHost();
		tabs.setOnTabChangedListener(this);

		TabSpec tspec1 = tabs.newTabSpec("Informations"); 
		tspec1.setIndicator("Informations");
		Intent infoIntent = new Intent(this, InfoCompteActivity.class);
		infoIntent.putExtra("userId",user.getId());
		tspec1.setContent(infoIntent);
		tabs.addTab(tspec1);

		TabSpec tspec2 = tabs.newTabSpec("Consoles"); 
		tspec2.setIndicator("Consoles"); 
		Intent consoleIntent = new Intent(this, ConsoleActivity.class);
		consoleIntent.putExtra("userId",user.getId());
		tspec2.setContent(consoleIntent);
		tabs.addTab(tspec2);

		TabSpec tspec3 = tabs.newTabSpec("Jeux"); 
		tspec3.setIndicator("Jeux"); 
		Intent jeuxIntent = new Intent(this, JeuxActivity.class);
		jeuxIntent.putExtra("userId",user.getId());
		tspec3.setContent(jeuxIntent);
		tabs.addTab(tspec3);

		tabs.setCurrentTab(0);
		TabColors.setUpTabColors(tabs);


	}

	public void onTabChanged(String tabId) {
		TabColors.setUpTabColors(tabs);

	}

	


}
